package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.Employee;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author liuquan
 * @program: springboot
 * @description: 配置类, 代替xml配置bean的类
 * @date 2021-02-08 11:34:36
 */

@RequestMapping("/employees")
@RestController   //等同于 @ResponseBody + @Controller 声明这个控制器的返回值都是json格式的
public class EmployeeController {
    @PostMapping
    public  Object save(Employee employee){
        employee.setId(555L);
        return employee;
    }

    @DeleteMapping
    public  Object delete(Long id){
        return new Employee(id,"hhh",15);
    }

    @PutMapping
    public  Object update(Employee employee){
        employee.setName("我是优化后的update操作");
        return employee;
    }


    @GetMapping("/{id}")
    public Object get(@PathVariable("id") Long empId){
        return new Employee(empId, "我是查询一个的操作",18);
    }



    @GetMapping
    public  Object list(){
        return Arrays.asList(
                new Employee(1L,"刘某人",18),
                new Employee(2L,"胡某人",17));
    }
}
